package com.demodis.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.List;

import com.demodis.domain.TblDeterPerson;
import com.demodis.util.DBUtil;

public class BaseDao {
	
	protected Connection conn = null;
	protected PreparedStatement ps = null;
	protected ResultSet rs = null;

	public boolean initUser() {
		String sql1 = "DELETE FROM TBL_USER WHERE USERNAME = 'admin';";
		String sql2 = "INSERT INTO TBL_USER(username, password, userRealName) VALUES('admin', '21232f297a57a5a743894a0e4a801fc3', 'admin');";
		int i = 0;
		try {
			conn = DBUtil.getConnection();
			ps = conn.prepareStatement(sql1);
			i = ps.executeUpdate();
			ps = conn.prepareStatement(sql2);
			i = ps.executeUpdate();
			System.out.println(i);
		} catch (Exception e) {
			e.printStackTrace();
			sql1 = "UPDATE TBL_USER SET PASSWORD = '21232f297a57a5a743894a0e4a801fc3', userRealName = 'admin' WHERE USERNAME = 'admin';";
			try {
				ps = conn.prepareStatement(sql1);
				i = ps.executeUpdate();
			} catch (SQLException e1) {
				e1.printStackTrace();
			}
		} finally {
			DBUtil.close(conn, ps, rs);
		}
		return i == 1 ? true : false;
	}

}
